"""
客户模块
"""
import unittest
from page.kehu.add_customer_care_page import AddCustomerCarePage
from page.kehu.clients_page import ClientsPage
from cases.base_case import BaseCase
from page.kehu.client_main_page import ClientMainPage
from page.kehu.add_client_page import AddClientPage
from page.kehu.customer_care_page import CustomerCarePage
from page.kehu.editorial_customer_care import EditorialCustomerCarePage
from page.index_page import IndexPage
from tools.utils import get_table_text
from tools.sjqd_way import read_data_from_excel
from  config.config import DATA_PATH
import os
class TestCrmKh(BaseCase):
    #合法输入必填项添加客户
    def test_crm_kh_add(self):
        self.data = read_data_from_excel(os.path.join(DATA_PATH,"datas.xls"), "添加客户")
        khmc,xm,sj = self.data[0]
        #点击客户按钮
        cp = IndexPage(self.driver)
        cp.click_kh_btn()
        #点击添加客户按钮
        ap = ClientMainPage(self.driver)
        ap.click_xjkh()
        #输入用客户名称
        bp = AddClientPage(self.driver)
        bp.input_khmc(khmc)
        #输入手机
        bp.input_sj(sj)
        #输入姓名
        bp.input_xm(xm)
        #点击保存
        bp.click_bc()
        #断言
        table_element = ap.get_table_element()
        KHMC= get_table_text(table_element,1,3)
        self.assertEqual(khmc,KHMC,"断言失败")


    #选择年营业额第一个添加客户
    def test_crm_kh_add_nyye_one(self):
        self.data = read_data_from_excel(os.path.join(DATA_PATH,"datas.xls"), "添加客户")
        khmc, xm, sj = self.data[1]
        # 点击客户按钮
        cp = IndexPage(self.driver)
        cp.click_kh_btn()
        # 点击添加客户按钮
        ap = ClientMainPage(self.driver)
        ap.click_xjkh()
        #选择年营业额
        bp = AddClientPage(self.driver)
        bp.choose_nyye(1)
        # 输入用客户名称
        bp.input_khmc(khmc)
        # 输入手机
        bp.input_sj(sj)
        # 输入姓名
        bp.input_xm(xm)
        # 点击保存
        bp.click_bc()
        # 断言
        table_element = ap.get_table_element()
        KHMC= get_table_text(table_element,1,3)
        self.assertEqual(khmc,KHMC,"断言失败")


    #客户池领取客户
    def test_kh_khc_lqkh(self):
        text = "领取成功"
        # 点击客户按钮
        cp = IndexPage(self.driver)
        cp.click_kh_btn()
        # 点击客户池
        ap = ClientMainPage(self.driver)
        ap.click_khc()
        #点击领取客户
        bp=ClientsPage(self.driver)
        bp.click_lq()
        # 断言
        text1 = bp.get_element_text()
        self.assertIn(text,text1,"断言失败")

    #添加客户关怀
    def test_crm_khgh_aad(self):
        self.data = read_data_from_excel(os.path.join(DATA_PATH,"datas.xls"), "添加客户关怀")
        kh,lxr,ghzt,ghrq = self.data[0]
        # 点击客户按钮
        cp = IndexPage(self.driver)
        cp.click_kh_btn()
        # 点击客户关怀
        ap = ClientMainPage(self.driver)
        ap.click_khgh()
        #点击新建关怀
        bp = CustomerCarePage(self.driver)
        bp.click_xjgh()
        #输入客户
        cp = AddCustomerCarePage(self.driver)
        cp.input_kh(kh)
        #输入联系人
        cp.input_lxr(lxr)
        #输入关怀主题
        cp.input_ghzt(ghzt)
        #输入关怀日期
        cp.input_ghrq(ghrq)
        #点击保存
        cp.click_bc()
        # 断言
        table_element = bp.get_table_element()
        GHZT = get_table_text(table_element, 1, 2)
        self.assertEqual(ghzt, GHZT, "断言失败")

    #编辑客户关怀
    def test_crm_kh_khgh_bjkhgh(self):
        self.data = read_data_from_excel(os.path.join(DATA_PATH,"datas.xls"), "编辑客户关怀")
        kh, lxr, ghzt, ghrq, zxr, ghlr, bz = self.data[0]
        # 点击客户按钮
        cp = IndexPage(self.driver)
        cp.click_kh_btn()
        # 点击客户关怀
        ap = ClientMainPage(self.driver)
        ap.click_khgh()
        #点击编辑客户关怀
        bp = CustomerCarePage(self.driver)
        bp.click_bj()
        #输入客户
        dp = EditorialCustomerCarePage(self.driver)
        dp.input_kh(kh)
        #输入联系人
        dp.input_lxr(lxr)
        #输入关怀主题
        dp.input_ghzt(ghzt)
        #输入关怀日期
        dp.input_ghrq(ghrq)
        #输入执行人
        dp.input_zxr(zxr)
        #输入关怀内容
        dp.input_ghlr(ghlr)
        #输入备注
        dp.input_bz(bz)
        #点击保存
        dp.click_bc()
        #断言
        table_element = bp.get_table_element()
        GHZT = get_table_text(table_element, 1, 2)
        self.assertEqual(ghzt, GHZT, "断言失败")

if __name__ == '__main__':
    unittest.main()